package com.scedu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.scedu.entity.Permission;
import com.scedu.entity.Role;
import com.scedu.entity.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sc
 * @since 2020-04-21
 */
public interface UserDao extends BaseMapper<User> {
   /**
      * 根据用户ID查询用户权限
      * @param uid
      * @return
      */
    @Select("SELECT * FROM ems_permission where id IN (\n" +
            "SELECT permission_id FROM ems_role_permission WHERE role_id IN(\n" +
            "SELECT role_id FROM ems_user_role WHERE user_id=#{uid})\n" +
            ") ")
    List<Permission> findPermissionByUid(String uid);

    /**
     * 根据用户ID查询用户角色
     * @param uid
     * @return
     */
    @Select("SELECT * FROM ems_role where id IN \n" +
            "(SELECT role_id FROM ems_user_role WHERE user_id=#{uid}\n" +
            ") ")
    List<Role> findRolesByUid(String uid);
}
